package org.dromara.apartment.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.apartment.domain.vo.PaymentTypeVo;
import org.dromara.apartment.domain.bo.PaymentTypeBo;
import org.dromara.apartment.service.IPaymentTypeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 支付方式
 * 前端访问路由地址为:/apartment/paymentType
 *
 * @author ckj
 * @date 2025-06-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/paymentType")
public class PaymentTypeController extends BaseController {

    private final IPaymentTypeService paymentTypeService;

    /**
     * 分页查询支付方式列表
     */
    @SaCheckPermission("apartment:paymentType:list")
    @GetMapping("/page")
    public TableDataInfo<PaymentTypeVo> page(PaymentTypeBo bo, PageQuery pageQuery) {
        return paymentTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询支付方式列表
     */
    @SaCheckPermission("apartment:paymentType:list")
    @PostMapping("/list")
    public R<List<PaymentTypeVo>> list(@RequestBody PaymentTypeBo bo) {
        return R.ok(paymentTypeService.queryList(bo));
    }

    /**
     * 获取支付方式详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("apartment:paymentType:query")
    @GetMapping("/{id}")
    public R<PaymentTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(paymentTypeService.queryById(id));
    }

    /**
     * 新增支付方式
     */
    @SaCheckPermission("apartment:paymentType:add")
    @Log(title = "支付方式", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PaymentTypeBo bo) {
        return toAjax(paymentTypeService.insertByBo(bo));
    }

    /**
     * 修改支付方式
     */
    @SaCheckPermission("apartment:paymentType:edit")
    @Log(title = "支付方式", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PaymentTypeBo bo) {
        return toAjax(paymentTypeService.updateByBo(bo));
    }

    /**
     * 删除支付方式
     *
     * @param ids 主键串
     */
    @SaCheckPermission("apartment:paymentType:remove")
    @Log(title = "支付方式", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(paymentTypeService.deleteWithValidByIds(List.of(ids), true));
    }
}
